package com.live.stamp.base.validation;

import com.hikeSoft.common.utils.BaseUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.container.core.common.BusinessException;

/**
 * 手机号验证处理器
 */
public class PhoneHandle extends ParamHandler {
    private static final Logger logger = LoggerFactory.getLogger(PhoneHandle.class);

    @Override
    protected ValidationEnum getParamHandleType() {
        return ValidationEnum.PHONE;
    }

    @Override
    protected void echo(String paramName, Object param) {
        String phone = (String)param;
        if(BaseUtils.isBlank(phone)){
            logger.error("PhoneHandle class -> param of phone is blank!");
            throw new BusinessException("手机号为空");
        }
        if(!BaseUtils.isMobileNo(phone)){
            logger.error("PhoneHandle class -> format of phone:{} is error!", phone);
            throw new BusinessException("手机号格式不正确");
        }
    }
}
